package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.entity.TRuleFrequency;
import com.pubinfo.passbook.common.model.dto.rule.RuleFrequencyParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TRuleFrequencyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("frequency")
@Api(tags = "规则频次管理")
@Slf4j
public class RuleFrequencyContoller {
  @Autowired
  TRuleFrequencyService frequencyService;
  
  @Autowired
  UserInfoService userInfoService;
  
  @PostMapping("list")
  @ApiModelProperty("查询规则频次列表")
  public JsonResult<MyPage<TRuleFrequency>> getFrequency(@RequestBody RuleFrequencyParam param) {
    
    return JsonResult.page(frequencyService.listRuleFrequency(param, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo()));
  }
  
  @PostMapping("save")
  @ApiModelProperty("新增规则频次")
  public JsonResult<String> saveFrequency(@RequestBody TRuleFrequency frequency) {
    return frequencyService.saveRuleFrequency(frequency, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo());
  }
  
  @DeleteMapping("remove")
  @ApiModelProperty("删除规则频次")
  public JsonResult<String> removeFrequency(String id) {
    return frequencyService.removeRuleFrequency(id, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo());
  }
  
  @PostMapping("update")
  @ApiModelProperty("修改规则频次")
  public JsonResult<String> updateFrequency(@RequestBody TRuleFrequency frequency) {
    return frequencyService.updateRuleFrequency(frequency, userInfoService.getCurrentUserInfo(), userInfoService.getRoleInfo());
  }
}
